package aware.util.dao.oracle;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;



import aware.util.dao.oracle.OracleUserDAO;
import aware.util.dao.DAOFactory;
import aware.util.dao.SQLStoredProcedureExecutor;
import aware.util.dao.UserDAO;

public class OracleDAOFactory extends DAOFactory {
	public static final String DRIVER = "COM.cloudscape.core.RmiJdbcDriver";
	public static final String DBURL = "jdbc:cloudscape:rmi://localhost:1099/CoreJ2EEDB";

	// method to create Cloudscape connections
	public static Connection createConnection() {

		Connection conn = null;
		try {
			Context initContext = new InitialContext();		
			Context envContext  = (Context)initContext.lookup("java:/comp/env");
			if (envContext == null)
				throw new RuntimeException("Error: No Context");
			DataSource ds = (DataSource)envContext.lookup("jdbc/awareOracle");
			if (ds == null)
				throw new RuntimeException("Error: No DataSource");
			conn = ds.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (NamingException e) {
			e.printStackTrace();
		}

		return conn;
	}

	@Override
	public UserDAO getUserDAO() {
		return new OracleUserDAO();
	}

	@Override
	public UserDAO getSQLStoredProcedureExecutor(String procedureNamePattern) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SQLStoredProcedureExecutor getSQLStoredProcedureExecutor(String catalog,
			String procedureNamePattern) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SQLStoredProcedureExecutor getSQLStoredProcedureExecutor(String catalog,
			String schemaPattern, String procedureNamePattern) {
		// TODO Auto-generated method stub
		return null;
	}

}
